package com.ruoyi.web.controller.reseller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.reseller.VsDramasResellerOrder;
import com.ruoyi.system.service.reseller.IVsDramasResellerOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 分销订单Controller
 * 
 * @author zzx
 * @date 2024-04-27
 */
@Api(tags = "分销订单")
@RestController
@RequestMapping("/reseller/order")
public class VsDramasResellerOrderController extends BaseController
{
    @Autowired
    private IVsDramasResellerOrderService vsDramasResellerOrderService;

    /**
     * 查询分销订单列表
     */
    @ApiOperation("查询分销订单列表")
    @GetMapping("/list")
    public TableDataInfo list(VsDramasResellerOrder vsDramasResellerOrder)
    {
        startPage();
        List<VsDramasResellerOrder> list = vsDramasResellerOrderService.selectVsDramasResellerOrderList(vsDramasResellerOrder);
        return getDataTable(list);
    }

    /**
     * 导出分销订单列表
     */
//    @ApiOperation("导出分销订单列表")
    @Log(title = "分销订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasResellerOrder vsDramasResellerOrder)
    {
        List<VsDramasResellerOrder> list = vsDramasResellerOrderService.selectVsDramasResellerOrderList(vsDramasResellerOrder);
        ExcelUtil<VsDramasResellerOrder> util = new ExcelUtil<VsDramasResellerOrder>(VsDramasResellerOrder.class);
        util.exportExcel(response, list, "分销订单数据");
    }

    /**
     * 获取分销订单详细信息
     */
    @ApiOperation("获取分销订单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(vsDramasResellerOrderService.selectVsDramasResellerOrderById(id));
    }

    /**
     * 新增分销订单
     */
    @ApiOperation("新增分销订单")
    @Log(title = "分销订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasResellerOrder vsDramasResellerOrder, HttpServletRequest request)
    {
        if ("guest".equals(getLoginUser().getVsUser().getMode())) {
            return error();
        }
        if (!StringUtils.isEmpty(request.getHeader("Lang-Id"))) {
            Integer integer = Integer.valueOf(request.getHeader("Lang-Id"));
            vsDramasResellerOrder.setLangId(integer);
        }
        String orderSn = vsDramasResellerOrderService.insertVsDramasResellerOrder(vsDramasResellerOrder);
        if ("err".equals(orderSn)) {
            return AjaxResult.error("创建订单失败！");
        }
        Map map = new HashMap<>();
        map.put("orderSn", orderSn);
        return success(map);
    }

    /**
     * 修改分销订单
     */
//    @ApiOperation("修改分销订单")
    @Log(title = "分销订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasResellerOrder vsDramasResellerOrder)
    {
        return toAjax(vsDramasResellerOrderService.updateVsDramasResellerOrder(vsDramasResellerOrder));
    }

    /**
     * 删除分销订单
     */
//    @ApiOperation("删除分销订单")
    @Log(title = "分销订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(vsDramasResellerOrderService.deleteVsDramasResellerOrderByIds(ids));
    }
    @PostMapping("/selectCount")
    public AjaxResult selectCount(@RequestBody VsDramasResellerOrder vsDramasResellerOrder) {
        return AjaxResult.success(vsDramasResellerOrderService.selectCount(vsDramasResellerOrder));
    }

}
